/************************************************************
 * Project Name         [Thinking_In_Java]
 * File Name            [Example_03_File_Appender.java]
 * Creation Date        [09-Jul-2014]
 * 
 * Copyright© ge.y.yang@gmail.com All Rights Reserved
 * 
 * Work hard, play harder, think big and keep fit
 ************************************************************/
package pkg_09_io.basic;

import java.io.FileWriter;
import java.io.RandomAccessFile;

/**
 * 文件追加输入
 * 
 * @author 不落的太阳(Sean Yang)
 * @version 1.0
 * @since JDK 6
 * 
 */
public class Example_03_File_Appender {

	/**
	 * 使用RandomAccessFile追加
	 * 
	 * @param fileName
	 * @param content
	 * @throws Exception
	 */
	public static void appenderA(String fileName, String content)
			throws Exception {
		RandomAccessFile raf = new RandomAccessFile(fileName, "rw");

		long fileLength = raf.length();// 文件长度
		raf.seek(fileLength);// 将文件指针移到文件尾
		raf.writeBytes(content); // 写入内容
		raf.close();
	}

	/**
	 * 使用FileWriter追加
	 * 
	 * @param fileName
	 * @param content
	 * @throws Exception
	 */
	public static void appenderB(String fileName, String content)
			throws Exception {
		FileWriter fw = new FileWriter(fileName, true);
		fw.write(content);
		fw.close();
	}

}
